<template>
  <div class="container">
    <!-- 头部 -->
    <el-card class="header">
      <el-row type="flex" align="middle">
        <img
          v-errImg="require('@/assets/common/defaultImg.png')"
          style="width: 100px; border-radius: 50%"
          :src="avatar"
          alt=""
        >
        <div class="text">
          <p style="font-size: 20px">
            {{ compute }}，{{ name }} 用户，今天也是美好的一天~
          </p>
          <p style="font-size: 17px; color: #999">管理员 | 翻斗乐园 - 管理部</p>
        </div>
      </el-row>
    </el-card>
    <!-- 内容 -->
    <div class="conent">
      <!-- 左边 -->
      <el-col :span="12">
        <el-card>
          <template #header>
            <span style="font-size: 25px">工作日历</span>
          </template>
          <el-calendar v-model="value" />
        </el-card>
        <!-- 公告 -->
        <Notice :name="name" />
      </el-col>
      <!-- 右边 -->
      <el-col :span="12" style="margin-left: 10px">
        <!-- 快捷操作 -->
        <el-card>
          <span class="speed">快速开始/便捷导航</span>
          <div class="btn">
            <el-button @click="$router.push('/page')">页面管理</el-button>
            <el-button @click="$router.push('/economic')">经济管理</el-button>
            <el-button @click="$router.push('/housing')">房产管理</el-button>
            <!-- <div class="sonBtn" style="width:100%"> -->
            <el-button @click="$router.push('/role')">角色管理</el-button>
            <el-button @click="$router.push('/customer')">客户管理</el-button>
            <el-button @click="$router.push('/authority')">权限管理</el-button>
            <!-- </div> -->
            <!-- style="margin-top:20px" -->
            <el-button @click="$router.push('/employees')">员工管理</el-button>
          </div>
        </el-card>
        <!-- echarts可视化 -->
        <el-card style="margin-top: 10px">
          <lineCharts />
        </el-card>
        <el-card style="margin-top: 10px">
          <img src="@/assets/commons/dash.jpg" alt="">
        </el-card>
        <el-card style="margin-top: 10px">
          <template #header>
            <span style="font-size: 20px">更新日志</span>
          </template>
          <el-collapse v-model="activeName" accordion>
            <el-collapse-item title="v3.8.4-2022-11-15" name="1">
              <div>1.优化首页</div>
              <div>2.首页基本功能实现</div>
            </el-collapse-item>
            <el-collapse-item title="v3.8.5-2022-11-15" name="2">
              <div>1.页面管理基本布局</div>
              <div>2.页面管理基本功能实现</div>
            </el-collapse-item>
            <el-collapse-item title="v3.8.6-2022-11-16" name="3">
              <div>1.权限管理基本功能实现</div>
              <div>2.优化权限管理</div>
              <div>3.优化员工管理</div>
            </el-collapse-item>
            <el-collapse-item title="v3.8.7-2022-11-16" name="4">
              <div>1.优化房产管理</div>
              <div>2.设置token过期</div>
            </el-collapse-item>
          </el-collapse>
        </el-card>
      </el-col>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getUserInfo, getPermission } from '@/api/user'
import lineCharts from './components/line.vue'
import Notice from './components/notice.vue'

export default {
  name: 'Dashboard',
  components: {
    lineCharts,
    Notice
  },
  data() {
    return {
      value: new Date(),
      activeName: '1'
    }
  },

  computed: {
    ...mapGetters(['name', 'avatar']),
    hour() {
      return new Date().getHours()
    },
    compute() {
      let res = ''
      if (this.hour >= 0 && this.hour < 12) {
        res = '早上好'
      } else if (this.hour >= 12 && this.hour <= 18) {
        res = '下午好'
      } else {
        res = '晚上好'
      }
      return res
    }
  },
  async created() {
    // 获取用户信息
    const res = await getUserInfo()
    await getPermission()
    // console.log(result)
    this.$store.commit('user/saveUserInfo', res)
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
  .text {
    margin-left: 20px;
  }
  .conent {
    display: flex;
    margin-top: 10px;
    .speed {
      font-size: 25px;
      border-bottom: 3px solid #8a97f8;
      padding-bottom: 10px;
    }
    .btn {
      margin-top: 30px;
      .el-button {
        padding: 20px 40px;
        font-size: 18px;
        margin: 18px 20px;
      }
      .sonBtn {
        margin-top: 20px;
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-evenly;
      }
    }
  }
}
</style>
